﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace QuickTuner.Util
{
    // TODO: Test this.

    // note: this file also exists in QuickTuner main UI project. Modify with care.
    public static partial class FrameworkExtensions
    {
        // a map function
        public static void ForEach<T>(this IEnumerable<T> @enum, Action<T> mapFunction)
        {
            foreach (var item in @enum) mapFunction(item);
        }

        public static void ForEach(this IEnumerable @enum, Action<object> mapFunction)
        {
            foreach (var item in @enum) mapFunction(item);
        }

        // shorthand for string.Format
        public static string F(this string @string, params object[] args)
        {
            return string.Format(@string, args);
        }

        // saves a string content into a memory stream
        public static MemoryStream ToMemoryStream(this string @string)
        {
            var bytes = Encoding.Default.GetBytes(@string);
            var ms = new MemoryStream(bytes);

            return ms;
        }
    }
}